//
//  ScrollBarCell.swift
//  JTYP
//
//  Created by Groot on 2017/11/28.
//  Copyright © 2017年 inspur. All rights reserved.
//

import SnapKit

class ScrollBarCell: UICollectionViewCell {
    
    private var selectedTitleColor: UIColor = UIColorFromRGB(rgbValue: 0xF77777)
    private var normalTitleColor: UIColor = UIColorFromRGB(rgbValue: 0x777777)
    
    var titleFontSize: CGFloat = 16.0
    
    static let Identifier = String(describing: ScrollBarCell.self)
    
    var titleLab: UILabel?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        customization()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        customization()
    }
    
    func customization() {
        titleLab = UILabel()
        titleLab?.font = UIFont.systemFont(ofSize: titleFontSize)
        titleLab?.textColor = normalTitleColor
        self.addSubview(titleLab!)
        
        titleLab?.snp.makeConstraints({ (make) in
            make.centerX.centerY.equalToSuperview()
        })
    }
    
    func updateCellWithItem(_ item: ScrollBarItem) {
        titleLab?.text = item.itemName
        isSelected = item.isSelected ?? false
    }
    
    func setTitleColor(normal: UIColor, selected: UIColor) {
        selectedTitleColor = selected
        normalTitleColor = normal
    }
    
    func setTitleSize(fontSize: CGFloat) {
        titleFontSize = fontSize
        titleLab?.font = UIFont.systemFont(ofSize: titleFontSize)
    }
    
    override var isSelected: Bool {
        didSet {
            titleLab?.textColor = isSelected ? selectedTitleColor : normalTitleColor
        }
    }
}

class ScrollBarItem {
    
    var itemID: String?
    var itemName: String?
    var isSelected: Bool?
    //var isDefault: Bool?
    
    init(itemName: String) {
        self.itemID = ""
        self.itemName = itemName
        self.isSelected = false
    }
    
}

